package viz.model.prefs.vos
{
	import flare.vis.data.Data;
	import flare.vis.data.EdgeSprite;
	import flare.vis.data.NodeSprite;
	
	import viz.model.IEncodeable;
	
	public class EdgePropVo implements IEncodeable
	{
		private var lineWidth:Number;
		private var lineColor:uint;
		private var targetLabelColor:uint;
		private var sourceLabelColor:uint;
		private var alpha:Number;
		private var arrowType:String;
		private var arrowHeight:Number;
		private var arrowWidth:Number;
		
		public function EdgePropVo( o:Object )
		{
			encode( o )
		}
		
		public function encode(o:Object):void{
			var xml:XML = o as XML;
			if(!xml)throw new Error("XML expected");
			lineWidth = Number( xml.lineWidth );
			lineColor = uint( xml.lineColor );
			targetLabelColor = uint( xml.targetLabelColor );
			sourceLabelColor = uint( xml.sourceLabelColor );
			alpha = Number( xml.alpha );
			arrowType = String( xml.arrowType );
			arrowHeight = Number( xml.arrowHeight );
			arrowWidth = Number( xml.arrowWidth );
			
		}
		
		public function setOutgoingEdges( node:NodeSprite ):void{
			hiLightNodeEdges( node, NodeSprite.OUT_LINKS );
		}
		
		public function setIncomingEdges( node:NodeSprite ):void{
			hiLightNodeEdges( node, NodeSprite.IN_LINKS );
		}
		
		public function setAllNodeEdges( node:NodeSprite ):void{
			hiLightNodeEdges( node, NodeSprite.ALL_LINKS );
		}
		
		public function setEdge( edge:EdgeSprite ):void{
			edge.alpha =  alpha;
			edge.lineColor =  lineColor;
			edge.arrowHeight =  arrowHeight;
			edge.arrowWidth =  arrowWidth;
			edge.arrowType =  arrowType;
			edge.lineWidth =  lineWidth;
			if(edge.target.props.label)edge.target.props.label.color = targetLabelColor;
			if(edge.source.props.label)edge.source.props.label.color = sourceLabelColor;
		}
		
		
		public function setAllEdges( data:Data ):void{
			
			
			data.edges.visit(function(e:EdgeSprite):void {
				e.alpha = alpha;
				e.lineColor = lineColor;
				e.lineWidth = lineWidth;
				e.arrowHeight = arrowHeight;
				e.arrowWidth = arrowWidth;
				e.arrowType = arrowType;
				
				
			});
			
			data.nodes.visit(function(n:NodeSprite):void {
				if(n.props.label)n.props.label.color = sourceLabelColor;				
			});
			
		
		}
		
		private function hiLightNodeEdges( node:NodeSprite, edgetype:uint ):void{
	
			node.visitEdges(function(e:EdgeSprite):void {
				e.alpha = alpha;
				e.lineColor = lineColor;
				e.lineWidth = lineWidth;
				e.arrowHeight = arrowHeight;
				e.arrowWidth = arrowWidth;
				e.arrowType = arrowType;
				if(e.source.props.label)
					e.source.props.label.color = sourceLabelColor;
				if(e.target.props.label)
					e.target.props.label.color = targetLabelColor;
				
				// thisbrings it to the top
				//_vis.marks.setChildIndex(e, _vis.marks.numChildren-1);
			}, edgetype);
		}
		
	}
}